//
//  NewCreateOneEorCViewController.m
//  shusheng
//
//  Created by rimi on 16/7/14.
//  Copyright © 2016年 yuying. All rights reserved.
//

#import "NewCreateOneEorCViewController.h"

#import "NewCreateOneEorCViewController.h"
#import "NewCreatEssay.h"
#import "NewCreatOneChapter.h"

@interface NewCreateOneEorCViewController ()

@end

@implementation NewCreateOneEorCViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)datas{
    if (_nameText.text.length == 0 || _idText.text.length == 0) {
        [self show:1];
        return;
    }
    
    if (_isNovelList) {

        //小说
        NewCreatOneChapter *creatOneChapter = [[NewCreatOneChapter alloc]init];
        creatOneChapter.novelName = _NovelNameString;
        creatOneChapter.novelId = _novelId;
        creatOneChapter.chapterId = _idText.text;
        creatOneChapter.chapterName = _nameText.text;
        NSLog(@"%@~~~~%@",_novelId,_idText.text);
        int result = [creatOneChapter creatchapterOfOneNovelid:_novelId chapterId:_idText.text chapterName:_nameText.text];
        
        
        [self show:result];
        NSLog(@"小说章节创建%d",result);

    }else{
        
        //文章
        NewCreatEssay *creatEssay = [[NewCreatEssay alloc]init];
        int result = [creatEssay creat:_idText.text essayname:_nameText.text];//创建部分
        
        [self show:result];
        NSLog(@"文章创建%d",result);

    }
}

- (void)show:(int)successOrError{
    
    switch (successOrError) {
        case 1:
            [MBProgressHUD showError:@"id或名字为空"];
            break;
        case 2:
            [MBProgressHUD showError:@"id重复"];
            break;
        case 3:
            [MBProgressHUD showSuccess:@"创建成功"];
            [self performSelector:@selector(removeself) withObject:nil afterDelay:2.0f];
            break;
        case 4:
            [MBProgressHUD showSuccess:@"离开"];
            [self performSelector:@selector(removeself) withObject:nil afterDelay:2.0f];
            break;
        case 5:
            [MBProgressHUD showSuccess:@"创建失败"];
           [self performSelector:@selector(removeself) withObject:nil afterDelay:2.0f];
        default:
            break;
    }
    
}

#pragma mark -- action --
#pragma mark --
- (IBAction)yesBtn:(UIButton *)sender {
    [self datas];
    
}


- (IBAction)noBtn:(UIButton *)sender {
    [self show:4];
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
    
}


- (void)removeself{
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}
@end
